import os
from tabulate import tabulate  # 添加tabulate库的导入

def calculate_file_stats(directory):
    file_stats = {}
    
    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            file_size = os.path.getsize(file_path)
            _, file_extension = os.path.splitext(file)
            
            if file_extension not in file_stats:
                file_stats[file_extension] = {'count': 0, 'size': 0}
            
            file_stats[file_extension]['count'] += 1
            file_stats[file_extension]['size'] += file_size
    
    return file_stats

def print_file_stats(stats):
    # 创建一个列表来存储表格数据
    table_data = []
    for ext, info in stats.items():
        table_data.append([ext, info['count'], info['size']])
    
    # 定义表格的表头
    headers = ["File type", "Count", "Total Size (bytes)"]
    
    # 使用tabulate库生成表格
    print(tabulate(table_data, headers=headers, tablefmt="grid"))

if __name__ == "__main__":
    directory = input("Enter the directory path: ")
    stats = calculate_file_stats(directory)
    print_file_stats(stats)